package org.mybatis.generator.codegen.mybatis3.javaservice;

import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.codegen.AbstractJavaGenerator;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class SimpleJavaServiceGenerator extends AbstractJavaGenerator{
	Properties properties;
	public SimpleJavaServiceGenerator(Properties properties){
		this.properties=properties;
	}
	 @Override
	    @SuppressWarnings({ "rawtypes", "unchecked" })
	    public List<CompilationUnit> getCompilationUnits() {
	        String pack = properties.getProperty("targetServicePackage");
	        String baseService=properties.getProperty("baseService");
	        String serviceName=
		            new StringBuffer(pack).append(".").
			          append(introspectedTable.getFullyQualifiedTable().getDomainObjectName()).  
			          append("Service").toString();
	        FullyQualifiedJavaType type = new FullyQualifiedJavaType(serviceName);
	        
	        TopLevelClass inter = new TopLevelClass(type);
	        inter.addAnnotation("@Slf4j");
	        inter.addAnnotation("@Service");
	        inter.setVisibility(JavaVisibility.PUBLIC);
	        inter.addImportedType(new FullyQualifiedJavaType  
	                     (introspectedTable.getBaseRecordType())); 
	        inter.addImportedType(new FullyQualifiedJavaType("org.springframework.stereotype.Service"));
	        inter.addImportedType(new FullyQualifiedJavaType("lombok.extern.slf4j.Slf4j"));
//	        inter.addImportedType(new FullyQualifiedJavaType
//	        		("org.slf4j.Logger"));
//	        inter.addImportedType(new FullyQualifiedJavaType
//	        		("org.slf4j.LoggerFactory"));
	        
	        inter.addImportedType(new FullyQualifiedJavaType(baseService));
	        inter.setSuperClass(new FullyQualifiedJavaType(baseService + "<" + introspectedTable.getFullyQualifiedTable().getDomainObjectName() + ">"));
	        
	        
//	        Field field = new Field();
//	        field.setVisibility(JavaVisibility.PRIVATE);
//	        field.setStatic(true);
//	        field.setFinal(true);
//	        field.setType(new FullyQualifiedJavaType("Logger"));
//	        field.setName("log=LoggerFactory.getLogger("+serviceName+".class)");
//	        inter.addField(field);
	        
	        List answer = new ArrayList();
	        answer.add(inter);  
	        return answer;  
	    }  
	 
}
